Total Complexity | 3 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
6 | |||
7 | @QueryHandler(GetUsersQuery) |
||
8 | export class GetUsersQueryHandler { |
||
9 | constructor( |
||
10 | @Inject('IUserRepository') |
||
11 | private readonly userRepository: IUserRepository |
||
12 | ) {} |
||
13 | |||
14 | public async execute(query: GetUsersQuery): Promise<UserView[]> { |
||
15 | let noLeavingDate = false; |
||
16 | if (query.activeOnly) { |
||
17 | noLeavingDate = true; |
||
18 | } |
||
19 | |||
20 | const users = await this.userRepository.findUsers( |
||
21 | query.withAccountant, |
||
22 | noLeavingDate |
||
23 | ); |
||
24 | const userViews: UserView[] = []; |
||
25 | |||
26 | for (const user of users) { |
||
27 | userViews.push( |
||
28 | new UserView( |
||
29 | user.getId(), |
||
30 | user.getFirstName(), |
||
31 | user.getLastName(), |
||
32 | user.getEmail(), |
||
33 | user.getRole(), |
||
34 | user.isAdministrativeEditable() |
||
35 | ) |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | return userViews; |
||
40 | } |
||
42 |